<?php
namespace wow\modelauth;
use \wow\model\dbcon as dbs,
\wow\model\tools;

/**
 *
 *
 * @Entity
 * @Table(name="account_banned")
 *
 */
class AccountBan{
	/**
	 * @Id @Column(type="integer", name="id")
	 */
	public $id;

	/**
	 * 
	 * @Id @Column(name="bandate", type="integer", length="40")
	 */
	public $bandate;

	/**
	 *
	 * @Column(name="unbandate", type="integer", length="40")
	 */
	public $unbandate = 0;

	/**
	 *
	 * @Column(name="bannedby", type="string")
	 */
	public $bannedby;
	
	/**
	 *
	 * @Column(name="banreason", type="string")
	 */
	public $banreason;
	
	/**
	 *
	 * @Column(name="active", type="boolean")
	 */
	public $active = true;
	

	

	public function setUnbanDateInMS($ms){
		$this->unbandate = $ms / 1000;
	}
	
	
	public function __construct($id, $bannedby, $banreason, $unbandate = 0, $active = true){
		$this->id = $id;
		$this->bandate = time();
		$this->bannedby = $bannedby;
		$this->banreason = $banreason;
		$this->unbandate = $unbandate;
		$this->active = $active;
	}

	
	static public function getActiveBansForUserId($id){
		dbs\AuthDB::load();
		$q = dbs\AuthDB::getEM()->createQuery(
		"select u from \wow\modelauth\AccountBan u 
		where u.id = ?1 AND u.active = true AND (u.unbandate > ?2 OR u.unbandate = 0)");
		$q->setParameter(1, $id);
		$q->setParameter(2, time());
		
		
		return $q->getResult();
	}

}
